package com.bauer.springboot.starter.configuration;

import com.bauer.springboot.starter.props.SftpProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @description:
 * @author: weirui
 * @create: 2019-12-06 12:52
 **/
@Configuration
@ConditionalOnClass(value = SftpProperties.class)
@EnableConfigurationProperties(SftpProperties.class)
public class SftpAutoConfiguration {

    private SftpProperties sftpProperties;


    /**
     * @description 通过构造函数自动注入
     * @author weirui
     * @date 2019/12/6 13:54
     */
    public SftpAutoConfiguration(SftpProperties sftpProperties) {
        this.sftpProperties = sftpProperties;
    }

    /**
     * 当存在 sftp.host时才会自动创建bean
     * @return
     */
    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "sftp", value = "host")
    public SftpTemplate getSftpTemplate() {
        return new SftpTemplate(sftpProperties);
    }
}
